package com.smarthospital.service.impl;

import com.smarthospital.dao.daoService.ReportDaoService;
import com.smarthospital.entity.pojo.Report;
import com.smarthospital.entity.pojo.User;
import com.smarthospital.service.ReportService;
import com.smarthospital.web.inteceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * create by sym  2021/5/4 16:30.
 */
@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDaoService reportDaoService;
    @Override
    public Map<String, List<Report>> querMyReports() {
        User user = LoginInterceptor.getUser();
        List<Report> list = reportDaoService.querMyReports(user.getRegisterId());
        return  list.stream().collect(Collectors.groupingBy(Report::getHospital));

    }

    /**
     * 根据医院id拉取报告  todo
     * @param hospitalId
     * @return
     */
    @Override
    public List<Report> getReportByHos(Long hospitalId) {
        //默认去拉取
        //将数据组装为标准格式
        List<Report> list = new ArrayList<>();
        //根据报告id确认数据是否重复
        //没重复的插入数据库
        //返回标准格式数据
        return list;
    }
}
